#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
#define NUM 1024
#define SEP " "
#define SIZE 64
const char *getusername()
{
const char*name=getenv("USER");
if(name) return name;
else return "none";
}

const char *gethostname()
{
const char*hostname=getenv("HOSTNAME");
if(hostname) return hostname;
else return "none";
}

const char *Getcwd()
{
const char*pwd=getenv("PWD");
if(pwd) return pwd;
else return "none";
}
int main()
{
while(1)
{
char usercommand[NUM];
char*argv[SIZE];
int argc=0;
printf("[%s@%s %s]#",getusername(),gethostname(),Getcwd());
char*r=fgets(usercommand,strlen(usercommand),stdin);
if(r==NULL) return 1;
usercommand[strlen(usercommand)-1]='\0';
argv[argc++]=strtok(usercommand,SEP);
while(argv[argc++]=strtok(NULL,SEP));
//for(int i=0;usercommand[i];i++)
//printf("%d:%s\n",i,usercommand[i]);
pid_t id=fork();
if(id<0) return 1;
else if(id==0)
{
execvp(argv[0],argv);
exit(1);
}
else
{
pid_t rid=waitpid(id,NULL,0);
if(rid>0){}
}
}

//for(int i=0;argv[i];i++)
//printf("%d : %s\n",i,argv[i]);
//printf("%s",usercommand);
return 0;
}
